<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../../lib/html5shiv.js?rev=@@hash"></script>
    <script type="text/javascript" src="../../lib/respond.min.js?rev=@@hash"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="../../lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/skin/blue/skin.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../ht-css/Project.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="../../lib/DD_belatedPNG_0.0.8a-min.js?rev=@@hash"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../ht-css/style-q.css"/>
    <title>区域配置</title>
    <style>

    </style>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 权限管理 <span class="c-gray en">&gt;</span>  账号管理 <span class="c-gray en">&gt;</span> 数据配置 <span class="c-gray en">&gt;</span>区域配置
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="Hui-iconfont">&#xe68f;</i></a></nav>
<article class="page-container" method="post">
    <form class="ml-20 mr-20">
        <div class="bg-1 bk-gray">
            <div class="pl-10 lh-50 f-16">
            </div>
            <!--<table class="table table-border table-bg table-sort">
                <thead>
                <tr class="text-c">
                    <th width="100"><input type="checkbox" value="" id="spu_all">&nbsp;全选</th>
                    <th width="50">序号</th>
                    <th>区域</th>
                </tr>
                </thead>
                <tbody class="shun">
                <tr>
                    <td><input type="checkbox" class="spuId mr-30"></td>
                    <td>1</td>
                    <td>北京区域</td>
                </tr>
                <tr>
                    <td><input type="checkbox" class="spuId mr-30"></td>
                    <td>2</td>
                    <td>北京区域</td>
                </tr>
                </tbody>
            </table>-->
            <table class="table table-border table-bg  table-sort " id="configurtiondatatable">
                <thead>
                <tr class="text-c">
                    <th><input type="checkbox" onclick="stoprop()" value="spu_all" id="spu_all">全选</th>
                    <th>序号</th>
                    <th>区域</th>
                </tr>
                </thead>
                <tbody class="shun">

                </tbody>
            </table>
            <div class="text-c pb-20 pt-10">
                <input type="button" class="btn btn-secondary radius size-S" onclick="addconfigurtion()" value="确&nbsp;&nbsp;认">
                <input type="button" class="btn radius size-S ml-10" onclick="removeThise()" value="取&nbsp;&nbsp;消">
            </div>
        </div>
    </form>
</article>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/layer/2.4/layer.js?rev=@@hash"></script>
<script type="text/javascript" src="../../static/h-ui/js/H-ui.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../static/h-ui.admin/js/H-ui.admin.js?rev=@@hash"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js?rev=@@hash"></script>
<!--表单验证-->
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/jquery.validate.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/validate-methods.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/messages_zh.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js?rev=@@hash"></script>
<script src="../../ht-js/frame/doT.min.js?rev=@@hash"></script>
<script src="../../ht-js/public.js?rev=@@hash"></script>
<!--验证token-->
<script src="../../ht-js/verifyToken.js?rev=@@hash"></script>
<script src="../../ht-js/Project.js?rev=@@hash"></script>
<script src="../../lib/pagination/jquery.pagination.js?rev=@@hash"></script>
<script>
    function removeThise() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
    function stoprop() {
        var timer = setTimeout(function() {
            var num = $("#datatable").find("tbody").find("input[type=checkbox]:checked").length;
            setBtnDis(num, $("#productManage"));
            clearTimeout(timer);
        }, 200)

        window.event ? window.event.cancelBubble = true : e.stopPropagation();
    }
    function setBtnDis(num, pnode) { //如果选中项为空时，置灰相关按钮
        if(num <= 0) {
            pnode.find(".goods_edit").attr("disabled", "disabled").addClass("dis_btn");
        } else {
            pnode.find(".goods_edit").removeAttr("disabled").removeClass("dis_btn");
        }
    }
var userid=sessionStorage.getItem("userids");
 configurtion()
 function configurtion() {
     $.ajax({
         url: root.accessInter.getWarehouseList,
         contentType: "application/json;charset=UTF-8",
         cache: false,  //禁用缓存
         type: "POST",
         dataType:'json',
         data: JSON.stringify({
             "userId":userid
         }),
         success: function (data) {
             console.log(data)
             detaiist(data);
         },
     });
 }

    /*表格渲染*/
    var dataSource = new Array();
    //table的数据源
    var table;   //table对象
    dataSource = [];

    function detaiist(data) {
        dataSource.splice(0, dataSource.length);//清空数组
        $.each(data.data, function (i, field) {
            var rowData = new Array();
            rowData.push(field.warehouseName);
            rowData.push(field.isContain);
            rowData.push(field.areaId);
            rowData.push(field.warehouseCode);
            dataSource.push(rowData);
        });
        initDataTable(dataSource);

        function initDataTable(dataSource) {
            var dttable = $('#configurtiondatatable').dataTable(); // 初始化dataTable，清空上一个值
            dttable.fnClearTable(); //清空一下table
            dttable.fnDestroy(); //还原初始化了的datatable
            $("#configurtiondatatable").DataTable({
                "fnDrawCallback" : function(){
                    this.api().column(1).nodes().each(function(cell,i){
                        cell.innerHTML = i+1;

                    });
                },
                "autoWidth": false,
                "ordering": false,
                "searching": false,
                "paging": false,
                "retrieve": true,
                "destroy": false,
                "bAutoWidth": false,
                "bLengthChange": false,
                "aLengthMenu": [10],
                "oLanguage": {
                    "sLengthMenu": "每页显示 _MENU_ 条记录",
                    "sZeroRecords": "抱歉， 没有找到",
                    "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                    "sInfoEmpty": "没有数据",
                    "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "前一页",
                        "sNext": "后一页",
                        "sLast": "尾页"
                    },
                    "sZeroRecords": "没有检索到数据",
                    "sProcessing": "<img src='./loading.gif' />",
                },
                data: dataSource,
                columnDefs: [
                    {
                        "visible": true,
                        "targets": 0
                    },
                    {
                        "render": function(data, type, row, meta) {
                            if(row[1]==false){
                                var val = '<span><td><input  class="regional"  type="checkbox" id="' + row[2] + '" name="regional" value = "' + row[3] + '"></td></span>';
                                return val;
                            }else {
                                var val = '<span><td><input  class="regional" checked ="checked"  type="checkbox" name="regional" id="' + row[2] + '" value = "' + row[3] + '"></td></span>';
                                return val;
                            }

                        },
                        "targets": 0
                    },
                    {
                        "render": function(data, type, row, meta) {
                            var val = row[0] ;
                            return val;
                        },
                        "targets": 2
                    },


                ],
                "fnInitComplete": function(oSettings, json) {
                    setBtnDis(0, $("#productManage"));
                    $("#datatable").on("change", '.regional', function() {
                        var num = $(".shun").find("input[type=checkbox]:checked").length;
                        setBtnDis(num, $("#productManage"));
                    });

                }
            });
        };
    }

    function fatherselect(){
       var tagNamesObj=document.getElementsByName("regional");
       var  obj=document.getElementById("spu_all");
        for(i=0;i<tagNamesObj.length;i++){
            if(tagNamesObj[i].checked){
                obj.checked = true;

            }

        }
    }
    /*$(".regional").click(clickPicToArt);
    function clickPicToArt() {
        console.log("11111111111111111111111111")

    }*/
//保存
    function addconfigurtion() {
        var val=$('input:checkbox[name="regional"]:checked').val();
        if(val==null){ //是否被选中

            $.Huimodalalert('请选择区域！',2000);
        }
        var objArr = [];
        var curObj={}
        var regional=document.getElementsByName("regional");
        for(var  i=0;i<regional.length;i++){
            if(regional[i].checked==true) {
                curObj = {
                    "areaId": regional[i].id,
                    "warehouseCode": regional[i].value
                }
                objArr.push(curObj)

            }
        }
       /* root.accessInter.saveAreaConfig*/
        $.ajax({
            url: root.accessInter.saveAreaConfig,
            contentType: "application/json;charset=UTF-8",
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            data: JSON.stringify({
                "userId":userid,
                "configInfos":objArr
            }),
            success: function (data) {
                if(data.errorCode==0){
                    $.Huimodalalert('配置成功！',2000);
                    setTimeout( function () {
                        var index =  parent.location.reload();
                        parent.layer.close(index)
                    },1000);
                }
            },
        });
    }
    //父级框选中
    /*fk()
    function fk(){
        if($(".regional:checked").length==$(".regional").length){
            $("#spu_all").prop("checked",true);
        }else{
            $("#spu_all").prop("checked",false);
        }
    }*/
</script>
</body>
</html>